<?php
namespace app\portal\controller;

use cmf\controller\HomeBaseController;
use app\admin\service\ApiService;
use think\Db;

class NoticeController extends HomeBaseController
{

	//公告动态页面
	public function index()
	{

		$img = Db::name('img')->find(1);
		$this->assign('img',$img);

		$data1 = Db::name('notice')
		->where(['sort_id'=>1,'delete_time'=>0])
		->order('time desc')
		->select()
		->toArray();
		$data2 = Db::name('notice')
		->where(['sort_id'=>2,'delete_time'=>0])
		->order('time desc')
		->select()
		->toArray();
		$sort = Db::name('notice_sort')
		->order('id')
		->select()
		->toArray();
		$post = $this->request->param('sel',0,'intval');
		if (!empty($post)) {
			$this->assign('sel',$post);
		}else{
			$this->assign('sel',1);
		}
		$this->assign('sort',$sort);
		$this->assign('data1',$data1);
		$this->assign('data2',$data2);


		return $this->fetch();
	}
	//公告动态详情页面
	public function detail()
	{	
		$img = Db::name('img')->find(1);
		$this->assign('img',$img);
		
		$userid = cmf_get_current_user_id();
		$msg_id = $this->request->param('msg_id', 0, 'intval');
        if (!empty($msg_id)) {
            $res = Db::name('new_msg_user')->where(['user_id'=>$userid,'msg_id'=>$msg_id])->find();
            if(!$res){
                Db::name('new_msg_user')->insert(['user_id'=>$userid,'msg_id'=>$msg_id]);
            }
        }
		$sort = Db::name('notice_sort')
		->order('id')
		->select()
		->toArray();
		$this->assign('sort',$sort);

		
		$id = $this->request->param('id',0,'intval');

		$data = Db::name('notice')
            ->alias('a')
            ->join('cmf_notice_sort b','a.sort_id=b.id')
            ->field('a.*,b.name')
            ->where('a.id',$id)
            ->find();

		if ($data == null) {
			$this->error('页面不存在');
		}
		$this->assign('data',$data);
		return $this->fetch();
	}
	
}